package cn.jbit.smbms.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jbit.smbms.pojo.User;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * 拦截器
 * @author Administrator
 *
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User loginUser=(User)request.getSession().getAttribute("loginUser");
        if (null==loginUser){
            request.getSession().setAttribute("message","没有权限访问，请先登录！");
            response.sendRedirect(request.getContextPath()+"/login");
            return false;
        }else{
            return true;
        }
    }
}
